#define RECCACHE_PAGESIZ 1024
#define RECCACHE_BUFSIZ 4096
#define RECCACHE_RECMINSIZ 20
struct recpage{
   struct recpage *next;
   struct recpage *listpre;
   struct recpage *listnext;
   int16 upper;
   int16 lower;
   uchar type;
#define PAGE_FULL 1
#define PAGE_HALF 2
#define PAGE_FREE 0
};
struct recitem{
   int id;
   int siz;
};
struct hashnode{
   int id;
   uint32 hash1;
   uchar flag;
#define HN_PIN 1
   int ksiz;
   int vsiz;
   struct recpage *rp;
   struct hashnode *left;
   struct hashnode *right;
   struct hashnode *pre;
   struct hashnode *next;
};
struct reccache{
    int nrec;
	int npage;
	int maxpage;
	int pagesiz;
	int nextid;
	struct hashnode **buckets;
	struct hashnode *freenodes;
	struct hashnode *first;
	int nbucket;
	struct recpage *freelist;
	struct recpage *fulllist;
	struct recpage *halflist;
};
struct recpage *recnewpage(struct reccache *rc);
struct hashnode* hashnodeput(struct reccache *rc,struct recpage *rp,int id,char *key,int ksiz,int vsiz);
struct recitem *recsearch(struct reccache *rc,struct recpage* rp,int id,int *num);
void hashnodefree(struct reccache *rc,struct hashnode *hn);

struct reccache *rcnew(int nbucket,int maxpage,int pagesiz);
void rcfree(struct reccache* rc);
int rcput(struct reccache *rc,char *key,int ksiz,char *val,int vsiz);
int rcremove(struct reccache *rc,char *key,int ksiz);
char* rcget(struct reccache *rc,char *key,int ksiz,char *buf,int *siz);
struct hashnode *getrecnode(struct reccache *rc,char *key,int ksiz,int *pos);
int rcgetval(struct reccache *rc,struct hashnode *hn,int pos,char *buf,int siz);